<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
</body>
<script src="../js/react.development.js"></script>
<script src="../js/react-dom.development.js"></script>
<script src="../js/babel.min.js"></script>
<script type="text/babel">
    class MyComponent extends React.Component{
        state = {
            username: '',
            password: '',
            opacity: 1
        }

        inputChange = (type, value) => {
            this.setState({ [type]: value });
        }

        unMount = () => {
            ReactDOM.unmountComponentAtNode(document.getElementById("app"))
        }

        componentDidMount(){
            console.log(1)
            this.timer = setInterval( ()=> {
                let opacity = this.state.opacity - 0.1;
                if ( opacity <= 0) opacity = 1;
                this.setState({opacity})
            }, 200 );
        }

        componentWillUnmount(){
            clearInterval(this.timer);
        }

        render(){
            return (
                <div>
                    <input onChange={ (event) => { this.inputChange('username', event.target.value) } } type="text" placeholder="用户名"/>
                    <input  onChange={ (event) => { this.inputChange('password', event.target.value)} } onBlur={ this.inputBlur } type="text" placeholder='密码'/>
                    <button onClick={ this.clickBtn }>登录</button>
                    <h1 style={{opacity: this.state.opacity }}>波哥</h1>
                    <button onClick={ this.unMount }>卸载</button>
                </div>
            )
        }
    }

    let app = (
        <div>
            <MyComponent></MyComponent>
        </div>
    )

    ReactDOM.render(app, document.getElementById('app'))

</script>
</html>